package com.base.card.controller;

import java.util.List;
import java.util.Arrays;

import com.base.card.domain.vo.TCryptCardVo;
import com.base.card.service.ITCryptCardService;
import com.base.common.annotation.Log;
import com.base.common.annotation.RepeatSubmit;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.base.common.core.controller.BaseController;
import com.base.common.core.domain.PageQuery;
import com.base.common.core.domain.R;
import com.base.common.core.validate.AddGroup;
import com.base.common.core.validate.EditGroup;
import com.base.common.enums.BusinessType;
import com.base.common.utils.poi.ExcelUtil;
import com.base.card.domain.bo.TCryptCardBo;
import com.base.common.core.page.TableDataInfo;

/**
 * 密码卡
 *
 * @author base
 * @date 2023-10-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/card/cryptCard")
public class TCryptCardController extends BaseController {

    private final ITCryptCardService iTCryptCardService;

    /**
     * 查询密码卡列表
     */
// @SaCheckPermission("card:cryptCard:list")
    @GetMapping("/list")
    public R<TableDataInfo<TCryptCardVo>> list(TCryptCardBo bo, PageQuery pageQuery) {
        return R.ok(iTCryptCardService.queryPageList(bo, pageQuery));
    }

    /**
     * 导出密码卡列表
     */
    //   @SaCheckPermission("card:cryptCard:export")
    @Log(title = "密码卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TCryptCardBo bo, HttpServletResponse response) {
        List<TCryptCardVo> list = iTCryptCardService.queryList(bo);
        ExcelUtil.exportExcel(list, "密码卡", TCryptCardVo.class, response);
    }

    /**
     * 获取密码卡详细信息
     *
     * @param cardCode 主键
     */
    //    @SaCheckPermission("card:cryptCard:query")
    @GetMapping("/{cardCode}")
    public R<TCryptCardVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String cardCode) {
        return R.ok(iTCryptCardService.queryById(cardCode));
    }

    /**
     * 新增密码卡
     */
//     @SaCheckPermission("card:cryptCard:add")
    @Log(title = "密码卡", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TCryptCardBo bo) {
        return toAjax(iTCryptCardService.insertByBo(bo));
    }

    /**
     * 修改密码卡
     */
    //   @SaCheckPermission("card:cryptCard:edit")
    @Log(title = "密码卡", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TCryptCardBo bo) {
        return toAjax(iTCryptCardService.updateByBo(bo));
    }

    /**
     * 删除密码卡
     *
     * @param cardCodes 主键串
     */
    //  @SaCheckPermission("card:cryptCard:remove")
    @Log(title = "密码卡", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cardCodes}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] cardCodes) {
        return toAjax(iTCryptCardService.deleteWithValidByIds(Arrays.asList(cardCodes), true));
    }
}
